Skip to content

fix(filelocker): remove stale .stop file when Lock times out#1373

Open
SAY-5 wants to merge 2 commits into
tus:mainfrom
SAY-5:fix-filelocker-stop-file-cleanup-on-timeout
Open

fix(filelocker): remove stale .stop file when Lock times out#1373
SAY-5 wants to merge 2 commits into
tus:mainfrom
SAY-5:fix-filelocker-stop-file-cleanup-on-timeout

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 12, 2026

Fixes #1372.

When Lock() creates a .stop file to signal release to the current holder and then times out without acquiring the lock, the .stop file was previously only removed by a successful Unlock() — which is never called for a failed acquisition. The leftover file persisted on disk until the next successful Unlock() of the same upload ID.

On filesystems where flock() can return ErrBusy spuriously (notably SMB/CIFS), failed acquisitions left permanent stale state that broke all subsequent retries with ERR_LOCK_TIMEOUT even when no other process held the lock.

This patch cleans up the .stop file directly in the ctx.Done() branch of Lock() and adds a regression test that asserts one.stop is gone after a contended Lock() times out without the held lock being released.

SAY-5 added 2 commits May 11, 2026 23:24
When Lock() creates a .stop file to signal release to the current
holder and then times out without acquiring the lock, the .stop file
was previously only removed by a successful Unlock() — which is never
called for a failed acquisition. The leftover file would persist on
disk until the next successful Unlock() of the same upload ID.

On filesystems where flock() can return ErrBusy spuriously (notably
SMB/CIFS), this caused failed acquisitions to leave permanent stale
state that broke all subsequent retries.

Clean up the .stop file directly in the ctx.Done() branch.

Fixes tus#1372.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

filelocker: stale .lock and .stop files not cleaned up on ERR_LOCK_TIMEOUT, causing permanent upload failure on network filesystems (SMB/CIFS)

1 participant